package com.tbit.uqbike.webmanager.controller;

import com.github.pagehelper.PageInfo;
import com.tbit.uqbike.object.pojo.RefundOpeLog;
import com.tbit.uqbike.object.pojo.RideOrderMoneyOpeLog;
import com.tbit.uqbike.object.pojo.statistics.ExportRideOrderMoneyOpeLog;
import com.tbit.uqbike.object.value.Page;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.RideOrderMoneyOpeLogService;
import com.tbit.uqbike.webmanager.util.Assert;
import com.tbit.uqbike.webmanager.util.PageHelperUtil;
import com.tbit.uqbike.webmanager.util.excel.ExportExcelUtil;
import com.tbit.uqbike.webmanager.util.excel.ExportExcelWrapper;
import com.tbit.utils.DateTimeUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 骑行订单修改记录(RideOrderMoneyOpeLog)表控制层
 *
 * @author jing
 * @since 2020-11-20 16:20:47
 */
@RestController
@RequestMapping("/rideordermoneyopelog")
public class RideOrderMoneyOpeLogController {
    /**
     * 服务对象
     */
    @Resource
    private RideOrderMoneyOpeLogService rideOrderMoneyOpeLogService;

    /**
     * 通过主键查询单条数据
     *
     * @param accountId 主键
     * @return 单条数据
     */
    @PostMapping("selectList")
    public JsonResult selectList(Integer accountId) {
        return JsonResult.ok(this.rideOrderMoneyOpeLogService.queryById(accountId));
    }

    @PostMapping("/queryPage")
    public JsonResult queryPage(RideOrderMoneyOpeLog rideorder) {
        Assert.notNull(rideorder.getAccountId(), "ver.areaId.notNull");
        Assert.notNull(rideorder.getStartTime(), "sugar.startRideDt.notNull");
        Assert.notNull(rideorder.getEndTime(), "sugar.endRideDt.notNull");
        rideorder.setPage(new Page(rideorder.getPageNO(), rideorder.getRowCount()));
        PageHelperUtil.initPage(rideorder.getPage());
        PageInfo<RefundOpeLog> pageInfo = new PageInfo(rideOrderMoneyOpeLogService.queryRideOrderMoneyOpeLog(rideorder));
        return JsonResult.ok(pageInfo.getList(), (int) pageInfo.getTotal());
    }

    @GetMapping("/export")
    public void export(RideOrderMoneyOpeLog rideorder, HttpServletResponse response) {
        Assert.notNull(rideorder.getAccountId(), "ver.areaId.notNull");
        Assert.notNull(rideorder.getStartTime(), "sugar.startRideDt.notNull");
        Assert.notNull(rideorder.getEndTime(), "sugar.endRideDt.notNull");
        List<ExportRideOrderMoneyOpeLog> exports = rideOrderMoneyOpeLogService.export(rideorder);
        ExportExcelWrapper<ExportRideOrderMoneyOpeLog> util = new ExportExcelWrapper<>();
        String filename = "订单修改记录" + DateTimeUtil.getNowTimeYMD();
        String[] columnNames = {"操作者名称", "操作者号码", "用户名", "用户号码", "订单编号", "修改前金额", "修改后金额", "备注", "操作时间"};
        util.exportExcel(filename, filename, columnNames, exports, response, ExportExcelUtil.EXCEL_FILE_2003);
    }
}